package web.suzy.oj.controller.msg;

import com.baomidou.mybatisplus.core.metadata.IPage;
import org.apache.shiro.authz.annotation.RequiresAuthentication;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;
import web.suzy.oj.common.result.ResultBean;
import web.suzy.oj.pojo.vo.UserMsgVO;
import web.suzy.oj.pojo.vo.UserUnreadMsgCountVO;
import web.suzy.oj.service.msg.UserMessageService;

import javax.annotation.Resource;

/**
 * YangSuzy 软件工作室
 * 类名: UserMessageController
 * 描述: ---- 待定 -----
 * 功能: 获取用户收到的消息
 *
 * @author YangSuzy
 * Date: 2022/11/18 18:07
 */
@RestController
@RequestMapping("/api/msg")
public class UserMessageController {
    @Resource
    private UserMessageService userMessageService;

    /**
     * 方法名: getUnreadMsgCount
     * 描述: 获取用户未读消息数
     *
     * @return web.suzy.oj.common.result.ResultBean<web.suzy.oj.pojo.vo.UserUnreadMsgCountVO>
     * @date 2022/11/18 18:08
     * @auther YangSuzy
     **/
    @RequestMapping(value = "/unread", method = RequestMethod.GET)
    @RequiresAuthentication
    public ResultBean<UserUnreadMsgCountVO> getUnreadMsgCount() {
        return userMessageService.getUnreadMsgCount();
    }


    /**
     * 方法名: cleanMsg
     * 描述: 根据消息类型清空一类消息，或根据消息ID清空一条消息
     *
     * @param type 消息类型
     * @param id   消息ID
     * @return web.suzy.oj.common.result.ResultBean<java.lang.Void>
     * @date 2022/11/18 22:49
     * @auther YangSuzy
     **/
    @RequestMapping(value = "/clean", method = RequestMethod.DELETE)
    @RequiresAuthentication
    public ResultBean<Void> cleanMsg(@RequestParam("type") String type,
                                     @RequestParam(value = "id", required = false) Long id) {
        return userMessageService.cleanMsg(type, id);
    }

    /**
     * 方法名: getCommentMsg
     * 描述: 获取用户接收的评论消息提示，根据未读在前、时间晚在前进行排序
     *
     * @param limit       每页显示数目
     * @param currentPage 当前页
     * @return web.suzy.oj.common.result.ResultBean<com.baomidou.mybatisplus.core.metadata.IPage < web.suzy.oj.pojo.vo.UserMsgVO>>
     * @date 2022/11/27 23:24
     * @auther YangSuzy
     **/
    @RequestMapping(value = "/comment", method = RequestMethod.GET)
    @RequiresAuthentication
    public ResultBean<IPage<UserMsgVO>> getCommentMsg(
            @RequestParam(value = "limit", required = false) Integer limit,
            @RequestParam(value = "currentPage", required = false) Integer currentPage) {
        return userMessageService.getCommentMsg(limit, currentPage);
    }

    /**
     * 方法名: getReplyMsg
     * 描述: 获取用户接收的回复消息提示，根据未读在前、时间晚在前进行排序
     *
     * @param limit       每页显示数目
     * @param currentPage 当前页
     * @return web.suzy.oj.common.result.ResultBean<com.baomidou.mybatisplus.core.metadata.IPage < web.suzy.oj.pojo.vo.UserMsgVO>>
     * @date 2022/11/27 23:26
     * @auther YangSuzy
     **/
    @RequestMapping(value = "/reply", method = RequestMethod.GET)
    @RequiresAuthentication
    public ResultBean<IPage<UserMsgVO>> getReplyMsg(
            @RequestParam(value = "limit", required = false) Integer limit,
            @RequestParam(value = "currentPage", required = false) Integer currentPage) {
        return userMessageService.getReplyMsg(limit, currentPage);
    }

    /**
     * 方法名: getLikeMsg
     * 描述: 获取用户接收的点赞消息提示，根据未读在前、时间晚在前进行排序
     *
     * @param limit       每页显示数目
     * @param currentPage 当前页
     * @return web.suzy.oj.common.result.ResultBean<com.baomidou.mybatisplus.core.metadata.IPage < web.suzy.oj.pojo.vo.UserMsgVO>>
     * @date 2022/11/27 23:27
     * @auther YangSuzy
     **/
    @RequestMapping(value = "/like", method = RequestMethod.GET)
    @RequiresAuthentication
    public ResultBean<IPage<UserMsgVO>> getLikeMsg(
            @RequestParam(value = "limit", required = false) Integer limit,
            @RequestParam(value = "currentPage", required = false) Integer currentPage) {
        return userMessageService.getLikeMsg(limit, currentPage);
    }
}
